﻿<cfsilent>
	<cfscript>
	
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		
		event.setArg("pageTitle", "试卷贴");
		
		/* 考试相关 */
		examId = event.getArg("EXID");
		examType = event.getArg("ExamType");
		
		/* 学校信息 */
		sql = "SELECT sch_name, sch_name_eng FROM t_school ";

		queryObj = new Query( datasource=application.dnsSlave );
			
		rs_school = queryObj.execute( sql=sql ).getResult();
		
		
		/* 考试安排信息 */
		sql = "SELECT 
				a.wid, a.wdidx, 
				b.cellidx, b.time_start, b.time_end, 
				c.course_name, c.course_code, 
				d.institute_short, d.institute_name, 
				e.academic_year, e.academic_term, e.term_start 
				FROM t_examtask a 
				INNER JOIN t_examcell b ON a.cellidx = b.cellidx 
				INNER JOIN t_course c ON a.cid = c.cid 
				INNER JOIN t_institute d ON d.institute_id = c.institute_id 
				INNER JOIN t_term e ON e.term_id = a.term_id 
				WHERE 
					a.task_exid = :examId 
					AND 
					a.task_prog = '3' ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="examId", value=examId, cfsqltype="cf_sql_char" );
		
		rs_exam = queryObj.execute( sql=sql ).getResult();
		
		
		/* 考场分布 */
		sql = "SELECT 
				count(*) student_count, b.classroom 
				FROM t_student_exam a 
				INNER JOIN t_classroom b ON a.cr_id = b.cr_id  
				WHERE 
					a.task_exid = :examId 
				GROUP BY b.cr_id, b.classroom
				ORDER BY b.cr_id ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="examId", value=examId, cfsqltype="cf_sql_char" );
		
		rs_place = queryObj.execute( sql=sql ).getResult();
		
		tagCode = "EXP-" & examId;
		
		/* 计算参考人数 */
		countNum = 0;
		
		for ( a=1; a LTE rs_place.recordCount; a++ ) {
			countNum += rs_place["student_count"][a];
		}
		

		/* 计算分页 */
		
		/* 默认显示行数及高度 */
		rowPerPage = 11;
		
		if ( rs_place.recordCount ) {
			
			/* 计算打印页数 */
			if ( rs_place.recordCount mod rowPerPage ) {
				totlePageCount = int(rs_place.recordCount/rowPerPage) + 1;
			}
			else {
				totlePageCount = int(rs_place.recordCount/rowPerPage);
			}
			
			pageRowBegin = 1;
			pageRowEnd = min(rowPerPage, rs_place.recordCount);
			
		}
		
	</cfscript>
</cfsilent>

<cfif rs_exam.recordCount>

	<cfloop from="1" to="#totlePageCount#" index="currentPage">
		
		<cfif currentPage GT 1><div class="page_break"></div></cfif>

		<div class="UIreportTitle">
			<h3>《<cfoutput>#rs_exam.course_name#</cfoutput>》<cfoutput>#dictAdvice.getMarkTurnName( examType )#</cfoutput> 试卷贴</h3>
		</div>
		
		<div class="UIreportFoot">
			<table class="big">
				<tr height="40">
					<td>开课学院： <cfoutput>#rs_exam.institute_name#</cfoutput></td>
					<td><cfoutput>#rs_exam.academic_year#</cfoutput> 学年 第 <cfoutput>#rs_exam.academic_term#</cfoutput> 学期</td>
					<td align="right">第 <cfoutput>#currentPage#</cfoutput> 页, 共 <cfoutput>#totlePageCount#</cfoutput> 页</td>
				</tr>
			</table>
		</div>

		<table class="UIreportTable">
			<tr>
				<td width="70">考试科目</td>
				<td align="center"><cfoutput>#rs_exam.course_name#</cfoutput></td>
				<td width="70">课程代码</td>
				<td align="center"><cfoutput>#rs_exam.course_code#</cfoutput></td>
				<td width="70">考试人数</td>
				<td align="center" width="49"><strong><cfoutput>#countNum#</cfoutput></strong></td>
				<td width="70">考场数</td>
				<td align="center" width="49"><strong><cfoutput>#rs_place.recordCount#</cfoutput></strong></td>
			</tr>
		</table>

		<div class="clear20px"><!--.--></div>
	
		<table class="UIrowSlide">
			
			<cfset row = 0 />
			<cfloop query="rs_place" startrow="#pageRowBegin#" endrow="#pageRowEnd#">
				<cfset row++ />
				<cfset currentRow = pageRowBegin + row - 1 />
				<tr>
					<td width="30" height="60" align="center"><cfoutput>#currentRow#</cfoutput></td>
					<td width="30" align="center"><cfoutput>#rs_exam.institute_short#</cfoutput></td>
					<td width="90" align="center" class="middel"><cfoutput>#rs_exam.course_code#</cfoutput></td>
					<td class="big" align="center"><cfoutput>#rs_exam.course_name#</cfoutput></td>
					<td width="160" class="small">
						第<cfoutput>#rs_exam.wid#</cfoutput>周<cfoutput>#mathAdvice.convertWeekDayToChinese( rs_exam.wdidx )#</cfoutput>
						(<cfoutput>#datetimeAdvice.formatDateString( mathAdvice.revertTaskWeekDay( rs_exam.term_start, rs_exam.wid, rs_exam.wdidx ), "YYYY-MM-DD")#</cfoutput>)
						<cfoutput>#datetimeAdvice.formatTimeString( rs_exam.time_start, "HH:MI" )#</cfoutput>-<cfoutput>#datetimeAdvice.formatTimeString( rs_exam.time_end, "HH:MI" )#</cfoutput>
					</td>
					<td align="center"><cfoutput>#rs_place.classroom#</cfoutput></td>
					<td width="45" class="large" align="center"><cfoutput>#rs_place.student_count#</cfoutput></td>
				</tr>
				<cfif row lt rowPerPage and ( pageRowEnd - pageRowBegin + 1 ) gt row >
					<tr class="breakline">
						<td colspan="6"></td>
					</tr>
				</cfif>
			</cfloop>
		</table>
		
		<cfset pageRowBegin = pageRowBegin + rowPerPage />
		<cfset pageRowEnd = pageRowEnd + rowPerPage />
		<cfif pageRowEnd gt rs_place.recordCount>
			<cfset pageRowEnd = rs_place.recordCount />
		</cfif>
		
		<div class="clear20px"><!--.--></div>
		
		<div class="UIreportFoot">
			<table>
				<tr>
					<td>打印时间 <cfoutput>#dateFormat(now(), "YYYY年MM月DD日")#</cfoutput></td>
					<td align="right"><img src="<cfoutput>#getContextRoot()#</cfoutput>/barcode/Print/<cfoutput>#tagCode#</cfoutput>.png" height="43"/></td>
				</tr>
			</table>
		</div>
		
	</cfloop>
	
</cfif>